package student;

import student.StudentEntity;

import javax.persistence.*;

public class PersistStudent {
    public static void main(String[] args) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("Student_details");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();

        StudentEntity s1 = new StudentEntity();
        s1.setS_id(1001);
        s1.setS_name("周经纬");
        s1.setS_age(20);

        StudentEntity s2 = new StudentEntity();
        s2.setS_id(1102);
        s2.setS_name("朱佳喜");
        s2.setS_age(20);

        StudentEntity s3 = new StudentEntity();
        s3.setS_id(1003);
        s3.setS_name("李永琪");
        s3.setS_age(20);

        em.persist(s1);
        em.persist(s2);
        em.persist(s3);

        em.getTransaction().commit();

        em.close();
        emf.close();

        System.out.println("添加成功");

    }
}
